﻿<UserControl x:Class="ScrumFactory.Projects.Burndown"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             
             xmlns:props="clr-namespace:ScrumFactory.Projects.Properties"
             
             
             xmlns:visualization="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:chartPrmtvs="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
             SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}"

             x:Name="thisView"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">

    <Grid HorizontalAlignment="Stretch" >

        <charting:Chart  Margin="0,10,0,0" HorizontalAlignment="Stretch">
                                    
            <charting:Chart.Axes>                                
                <charting:DateTimeAxis Orientation="X"  IntervalType="Days"   >
                    <charting:DateTimeAxis.AxisLabelStyle>
                        <Style TargetType="charting:AxisLabel">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="charting:AxisLabel">
                                        <TextBlock Text="{Binding StringFormat='{}{0:dd/M}'}" FontSize="8"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </charting:DateTimeAxis.AxisLabelStyle>
                </charting:DateTimeAxis>                
                <charting:LinearAxis Minimum="0" Orientation="Y" ShowGridLines="True">
                    <charting:LinearAxis.GridLineStyle>
                        <Style TargetType="{x:Type Line}">
                            <Setter Property="Stroke" Value="LightGray"/>
                        </Style>
                    </charting:LinearAxis.GridLineStyle>
                </charting:LinearAxis>               
            </charting:Chart.Axes>          
            
            <charting:Chart.Series>

                <charting:AreaSeries         
                    LegendItemStyle="{StaticResource HideLegendStyle}"
                    ItemsSource="{Binding ActualHoursAhead}"                    
                    IndependentValuePath="Date"
                    DependentValuePath="TotalHours">
                    <charting:AreaSeries.DataPointStyle>
                        <Style TargetType="Control">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Background" Value="LightGray"/>
                        </Style>
                    </charting:AreaSeries.DataPointStyle>
                </charting:AreaSeries>

                <charting:AreaSeries       
                    Title="{x:Static props:Resources.actual_hours}"
                    LegendItemStyle="{StaticResource HorizontalLegendStyle}"
                    ItemsSource="{Binding ActualHours}"                    
                    IndependentValuePath="Date"
                    DependentValuePath="TotalHours">
                    <charting:AreaSeries.DataPointStyle>
                        <Style BasedOn="{StaticResource GraphSerie1Style}" TargetType="Control">                            
                            <Setter Property="Width" Value="10"/>
                            <Setter Property="Height" Value="10"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type charting:AreaDataPoint}">
                                        <Ellipse        
                                                Cursor="Help" Stroke="{StaticResource GraphBorderBrush1}"
                                                StrokeThickness="3" Width="10" Height="10">
                                            <Ellipse.Fill>
                                                <SolidColorBrush Color="White"/>
                                            </Ellipse.Fill>                                            
                                            <Ellipse.ToolTip>
                                                <ToolTip >
                                                    <StackPanel>
                                                        <TextBlock Text="{x:Static props:Resources.Today}" FontWeight="Bold"/>
                                                        <TextBlock Text="{Binding Date, StringFormat={x:Static props:Resources.dd_MMM}}"/>
                                                        <TextBlock Text="{Binding TotalHours, StringFormat={x:Static props:Resources.N_hrs}}"/>
                                                    </StackPanel>
                                                </ToolTip>
                                            </Ellipse.ToolTip>
                                        </Ellipse>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsToday}" Value="False">
                                    <Setter Property="Width" Value="0"/>
                                    <Setter Property="Height" Value="0"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </charting:AreaSeries.DataPointStyle>
                    <charting:AreaSeries.PathStyle>
                        <Style TargetType="Path">
                            <Setter Property="StrokeThickness" Value="2" />
                            <Setter Property="Stroke">
                                <Setter.Value>
                                    <SolidColorBrush Color="{StaticResource Blue4Color}"/>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </charting:AreaSeries.PathStyle>
                </charting:AreaSeries>

                <charting:LineSeries                
                    Title="{x:Static props:Resources.planned_hours_to_finish_the_project}"
                    LegendItemStyle="{StaticResource HorizontalLegendStyle}"
                    ItemsSource="{Binding PlannedHours}"  
                    
                    IndependentValuePath="Date"                    
                    DependentValuePath="TotalHours">                      
                    <charting:LineSeries.PolylineStyle>
                        <Style TargetType="{x:Type Polyline}">
                            <Setter Property="StrokeThickness" Value="3"/>
                        </Style>
                    </charting:LineSeries.PolylineStyle>
                    <charting:LineSeries.DataPointStyle>
                        <Style BasedOn="{StaticResource GraphSerie2Style}" TargetType="Control">                                
                            <Setter Property="Width" Value="10"/>
                            <Setter Property="Height" Value="10"/>                                                          
                            <Setter Property="Template">                                
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type charting:LineDataPoint}">
                                        <Ellipse        
                                                Cursor="Help" x:Name="ellipse"
                                                Stroke="{StaticResource GraphBorderBrush2}" StrokeThickness="3" Width="10" Height="10" Fill="White">
                                            <Ellipse.ToolTip>
                                                <ToolTip>
                                                    <StackPanel>
                                                        <TextBlock x:Name="tooltip" FontWeight="Bold">
                                                            <TextBlock.Style>
                                                                <Style>
                                                                    <Setter Property="TextBlock.Text" Value="{Binding SprintNumber, StringFormat={x:Static props:Resources.sprint_N}}"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding IsLastSprint}" Value="True">
                                                                            <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.project_end}"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBlock.Style>
                                                        </TextBlock>
                                                        <TextBlock Text="{Binding Date, StringFormat='{}{0:dd/MMM}'}"/>
                                                        <TextBlock Text="{Binding TotalHours, StringFormat={x:Static props:Resources.N_hrs}}"/>
                                                    </StackPanel>                                                    
                                                </ToolTip>
                                            </Ellipse.ToolTip>
                                        </Ellipse>
                                        <ControlTemplate.Triggers>
                                            <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                <Setter TargetName="tooltip" Property="TextBlock.Text" Value="{x:Static props:Resources.Today}"/>
                                                <Setter TargetName="ellipse" Property="Ellipse.Stroke">
                                                    <Setter.Value>
                                                        <SolidColorBrush Color="{StaticResource Orange2Color}"/>
                                                    </Setter.Value>
                                                </Setter> 
                                            </DataTrigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>                                    
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </charting:LineSeries.DataPointStyle>
                </charting:LineSeries>

            </charting:Chart.Series>

        </charting:Chart>
        <ContentControl           
            Grid.Row="0"
            HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource LoadingAnimationContent}"/>

        <!-- MAIN INDICATORS -->
        <StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
            <TextBlock Width="100" TextAlignment="Center">
                <TextBlock
                    Foreground="{StaticResource LabelBrush}" HorizontalAlignment="Center"
                    FontFamily="{StaticResource WideFont}" FontSize="40" FontWeight="Bold"
                    Text="{Binding WalkedPct, StringFormat='{}{0:0}'}"/>
                <LineBreak/>
                <TextBlock
                    Foreground="{StaticResource LabelBrush}" HorizontalAlignment="Center"
                    FontSize="{StaticResource SmallFontSize}" FontWeight="Bold"
                    TextWrapping="Wrap"
                    Text="{x:Static props:Resources.walked}"/>
            </TextBlock>            
            <TextBlock 
                Style="{StaticResource IndicatorTextBlock}"
                DataContext="{Binding DeadlinePositionStatus}" Width="100" TextAlignment="Center"
                HorizontalAlignment="Center">
                <TextBlock
                    HorizontalAlignment="Center" TextAlignment="Center"
                    FontFamily="{StaticResource WideFont}" FontSize="40" FontWeight="Bold"
                    Text="{Binding ElementName=thisView, Path=DataContext.DeadlinePosition, StringFormat='{}{0:0}'}"/>
                <LineBreak/>
                <TextBlock
                    HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap"
                    FontSize="{StaticResource SmallFontSize}" FontWeight="Bold"
                    Text="{Binding ElementName=thisView, Path=DataContext.DeadlinePositionLabel}"/>                    
            </TextBlock>            
        </StackPanel>
        

        <!-- CONTROLS -->
        <StackPanel
            x:Name="controls"
            Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">            
                <TextBlock VerticalAlignment="Center" >
                    <Hyperlink Command="{Binding SetBaselineCommand}">
                        <TextBlock FontSize="{StaticResource SmallFontSize}">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Visibility" Value="Hidden"/>
                                    <Setter Property="Text" Value="{x:Static props:Resources.use_as_baseline}"/>
                                <Style.Triggers>
                                <DataTrigger Binding="{Binding IsComparePlanningBaseline}" Value="True">
                                    <Setter Property="Text" Value="{x:Static props:Resources.do_not_use_as_baseline}"/>
                                </DataTrigger>
                                    <DataTrigger Binding="{Binding IsMouseOver, ElementName=controls}" Value="True">
                                        <Setter Property="Visibility" Value="Visible"/>
                                    </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                        </TextBlock>
                    </Hyperlink>
                    
                </TextBlock>                     
                <ComboBox      
                    BorderThickness="0"
                    SelectedItem="{Binding ComparePlanning}"
                    ItemsSource="{Binding Plannings}">                
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Line X1="0" Y1="2" X2="15" Y2="2" VerticalAlignment="Center" Stroke="Red" StrokeThickness="4"  />
                                
                            <TextBlock VerticalAlignment="Center" FontSize="{StaticResource SmallFontSize}" Padding="2">                                
                                <TextBlock.Style>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="Text" Value="{Binding ., StringFormat={x:Static props:Resources.comparing_with_N}}"/>                                        
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding .}" Value="0">
                                                <Setter Property="Text" Value="{x:Static props:Resources.comparing_with_proposal}"/>
                                            </DataTrigger> 
                                            <DataTrigger Value="0">
                                                <DataTrigger.Binding>
                                                    <MultiBinding Converter="{StaticResource BindingEqualConverter}">
                                                        <Binding Path="." />
                                                        <Binding Path="Model.Baseline" ElementName="thisView" />
                                                    </MultiBinding>
                                                </DataTrigger.Binding>
                                                <Setter Property="FontWeight" Value="Bold"/>                                                
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                        </StackPanel>
                        
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            
            <StackPanel.Style>
                <Style TargetType="StackPanel">                    
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding CanChangeBaseline}" Value="False">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Style>
        </StackPanel>

        
    </Grid>
    
   
    
    
</UserControl>
